package com.ssm.controller;

import com.ssm.service.CardService;
import org.json.JSONObject;
import org.json.XML;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.rmi.RemoteException;

@Controller
public class CardController {
    @Autowired
    CardService cardService;
//    卡状态查询，如果卡状态未启用，需要先启用。如果已经启用，可以直接查看信息
    @RequestMapping("/CardStatus")
    @ResponseBody
    public String CardStatus() throws Exception {
        String s = cardService.CardStatus();
        System.out.println("s的值是："+s);
        return s;
 }
//    领卡启用返回：<ERR>00/01/失败原因</ERR>。00表示执行成功，01表示之前已经领卡，失败时直接返回中文的失败原因。
    @RequestMapping("/CardCollar")
    @ResponseBody
    public String CardCollar() throws RemoteException {
        Object object = cardService.CardCollar();
        JSONObject jsonObject = XML.toJSONObject(object.toString());
        System.out.println("jsonObject的值是："+object.toString());
        return jsonObject.toString();
    }

//    调用getAC01()方法来进行卡数据的查询
    @RequestMapping("/CardDataQuery")
    @ResponseBody
    public String CardDataQuery() throws Exception{
        String s = cardService.CardDataQuery();
        JSONObject jsonObject = XML.toJSONObject(s);
        System.out.println(jsonObject);
        String id = jsonObject.optString("AAC002");
        jsonObject.append("id",id);
       String str = cardService.CardStatus();
       jsonObject.append("state",str);
//        model.addAttribute("state",str);
//        System.out.println(jsonObject);
//        System.out.println("jsonObject的值是："+jsonObject);
        return jsonObject.toString();
    }
    //卡数据和相片指纹(无权限)
    @RequestMapping("/CardData")
    @ResponseBody
    public  String CardData() throws RemoteException {
        String s = cardService.CardData();
        System.out.println("s的值是："+s);
        JSONObject jsonObject = XML.toJSONObject(s);
        String string = jsonObject.toString(4);
        return  string;
    }
//    银行数据查询
    @RequestMapping("/CardDataBank")
    @ResponseBody
    public  String CardDataBank() throws RemoteException {
        String s = cardService.CardDataBank();
        System.out.println("s的值是："+s);
        JSONObject jsonObject = XML.toJSONObject(s);
        String string = jsonObject.toString(4);
        return  string;
    }
//    人员数据查询
    @RequestMapping("/CardPeopleData")
    @ResponseBody
    public  String CardPeopleData() throws RemoteException {
        String s = cardService.CardPeopleData();
        System.out.println("s的值是："+s);
        JSONObject jsonObject = XML.toJSONObject(s);
        String string = jsonObject.toString(4);
        return  string;
    }
//    相片数据查询(无权限调用)
    @RequestMapping("/CardPhoneData")
    @ResponseBody
    public  String CardPhoneData() throws RemoteException {
        String s = cardService.CardPhoneData();
        System.out.println("s的值是："+s);
        JSONObject jsonObject = XML.toJSONObject(s);
        String string = jsonObject.toString(4);
        return  string;
    }

    //    调用allDsjk()方法来正式挂失卡片
    @RequestMapping("/OfficialLossCard")
    @ResponseBody
    public String OfficialLossCard() throws Exception {
        String s1 = cardService.CardStatus();
        if (s1.equals("封存")){
            cardService.CardCollar();
        }
            Object o = cardService.OfficialLossCard();
            System.out.println(o.toString()+"卡挂失状态：");
        return o.toString();
    }
    //    补全卡信息
    @RequestMapping("/CompleteCardInformation")
    @ResponseBody
    public String CompleteCardInformation(String phone) throws RemoteException {
        phone="18614983029";
        System.out.println("phone的值是："+phone);
        String s = (String) cardService.CompleteCardInformation(phone);
        System.out.println("s的值是："+s);
        JSONObject jsonObject = XML.toJSONObject(s);
        String string = jsonObject.toString(4);
        System.out.println("string的值是："+string);
        return string;
    }
    @RequestMapping("/insertCard")
    @ResponseBody
    public  int insertCard(String pName, String pSex, String pSocialNumber, String pIDCard){
        int i = cardService.insertCard("bb", "1", "Pdhdajlj45", "412726199609120823");
            System.out.println("正在进行插入操作");
        return i;
    }
    @RequestMapping("/testaa")
    @ResponseBody
    public String testaa(){
        String str="41272619960912085";
        return str;
    }

}
